var ns, app;
app = new Vue({
    el: '#app',
    data: {
        list: [],
        form: {
            keywords: '',
            pageindex: 0,
            pagesize: 10,
            ProjectIDs: '',
            RoomIDs: '',
        },
        FullName: '',
        current_item_length: 0,
        is_searching: false,
        scroll_top: 0,
        can_scroll: false,
        searchbar_click: false,
        headerlist: []
    },
    methods: {

        do_select_project: function() {
            var that = this;
            ns.openWin('chooseproject_frm', '选择项目', {
                selecttype: 2
            });
        },

        open_work_Details: function(item) { //工单
            var that = this;
            ns.openWin('customerservicelist_frm', '工单记录', {
                id: item.RoomID,
                servicetype: 1,
                isviewdetail: false,
                bg:"#289FFF",
                txtcolor:"#ffffff",
            });
        },
        tel_phone: function(item) {
            api.call({
                type: 'tel_prompt',
                number: item.ownerPhone
            });
        },
        get_select_project: function(data) {
            var that = this;
            that.form.ProjectIDs = data.params.projectids;
            that.form.RoomIDs = data.params.roomids;
            that.FullName = data.params.name;
            console.log(JSON.stringify(that.FullName));
            that.headerlist = eval('(' + data.headerlist + ')')
            setTimeout(function() {
                that.form.pageindex = 0;
                // that.get_data();
                var top_h = $api.offset($api.byId('topheadercontent')).h+10
                $api.css($api.byId('topheader'), 'height:' + top_h + 'px');
                $api.css($api.byId('main_refresh'), 'margin-top:' + top_h + 'px');
            }, 500);
        },
        // init_FullName: function() {
        //     var that = this;
        //     if (that.FullName == '') {
        //         that.FullName = '请选择资源信息';
        //     }
        // },
        openWin: function(item, params) {
            var that = this;
            if (item.url == '') {
                return;
            }
            params = params || {
                status: -1
            };
            ns.openWin(item.url, item.name, params);
        },
        // do_open_header: function(item) {
        //     var that = this;
        //     if (!item.isParent) {
        //         return;
        //     }
        //     ns.openWin('chooseproject_frm', '选择项目', {
        //         parentid: item.id,
        //         selecttype: 2
        //     });
        // },
        init_search: function() {
            var that = this;
            var searchBar = document.querySelector(".aui-searchbar");
            var searchBarInput = document.querySelector(".aui-searchbar input");
            var searchBarBtn = document.querySelector(".aui-searchbar .aui-searchbar-btn");
            var searchBarClearBtn = document.querySelector(".aui-searchbar .aui-searchbar-clear-btn");
            searchBarInput.onclick = function() {
                searchBarBtn.style.display = 'block';
                searchBarBtn.style.marginRight = 0;
                searchBarBtn.textContent = "搜索";
                searchBarBtn.classList.add("aui-text-info");
                if (searchBarInput.value == '') {
                    searchBarClearBtn.style.display = 'none';
                    searchBarBtn.style.display = 'none';
                } else {
                    searchBarClearBtn.style.display = 'block';
                    searchBarBtn.style.display = 'block';
                }
            }
            searchBarInput.oninput = function() {
                if (searchBarInput.value == '') {
                    searchBarClearBtn.style.display = 'none';
                    searchBarBtn.style.display = 'none';
                } else {
                    searchBarClearBtn.style.display = 'block';
                    searchBarBtn.style.display = 'block';
                }
            }
            searchBarClearBtn.onclick = function() {
                searchBarBtn.style.display = 'none';
                this.style.display = 'none';
                that.form.keywords = '';
                searchBarBtn.classList.remove("aui-text-info");
                searchBarBtn.textContent = "";
            }
            searchBarBtn.onclick = function() {
                that.do_search();
            }
            searchBarInput.onkeypress = function(e) {
                var keycode = e.keyCode;
                if (keycode == '13') {
                    e.preventDefault();
                    searchBarInput.blur();
                    that.do_search();
                }
            }
        }
    }
});
apiready = function() {
    api.parseTapmode();
    ns = window.Foresight.Util;
    // app.init_FullName();
    // app.init_search();
    app.list = api.pageParam.list || [];
    // console.log(JSON.stringify(api.pageParam));
    app.get_select_project(api.pageParam);
    api.addEventListener({
        name: 'do_choose_project_complete'
    }, function(ret) {
        app.get_select_project(ret.value);
    })
    ns.init_pull();
};
